from pathlib import Path

from StressAna.UI.UIManager import *
from StressAna.UI.StressBySqlite import StressSqlite3
from StressAna.UI.StressByMysql import StressMysql
from StressAna.UI.StressByCSV import Stress_csv

logger = Globalvariables.LOG.get_logger("main")

def main():
    app = QtWidgets.QApplication(sys.argv)
    Main = ContrastMain()
    Main.show()
    sys.exit(app.exec())


def stress_sqlite3():
    if not Path(Globalvariables.DB_PATH).exists():
        logger.info('不存在数据库，请解压database.zip')
        return
    app = QtWidgets.QApplication(sys.argv)
    Main = StressSqlite3()
    Main.show()
    sys.exit(app.exec())


def stress_mysql():
    app = QtWidgets.QApplication(sys.argv)
    Main = StressMysql()
    Main.show()
    sys.exit(app.exec())


def stress_csv():
    app = QtWidgets.QApplication(sys.argv)
    Main = Stress_csv()
    Main.show()
    sys.exit(app.exec())


if __name__ == '__main__':
    argv = sys.argv[1:]
    if argv and argv[0] == '0':
        logger.info('文件模式')
        main()
    if argv and argv[0] == '1':
        logger.info('Mysql数据库模式')
        stress_mysql()
    else:
        logger.info('CSV文件模式')
        stress_csv()
    # stress_sqlite3()
